cap program drop labelingvarsfinal
program define labelingvarsfinal

    local input_string = "`1'"
    
    *labelling
	*drop all labels
	* List all variables
	qui ds *`input_string'*
	* Store the list in a local macro
	local vars `r(varlist)'

	* Loop through each variable and clear its label
	foreach var of local vars {
		label variable `var' ""
	}

	* List all variables
	qui ds
	* Store the list in a local macro
	local vars `r(varlist)'
	* Loop through each variable
	foreach var of local vars {
		if strpos("`var'", "`input_string'") {
			label variable `var' "`input_string'"
            if strpos("`var'", "Ps") {
                local current_label : variable label `var'
                label variable `var' "predicted `current_label'"
            }
            if strpos("`var'", "ln") {
                local current_label : variable label `var'
                label variable `var' "ln`current_label'"
            }
            if strpos("`var'", "k") {
                local current_label : variable label `var'
                label variable `var' "stocks of `current_label'"
            }
            if strpos("`var'", "NOT") {
                local current_label : variable label `var'
                label variable `var' "non-`current_label'"
            }
            if strpos("`var'", "shr") {
                local current_label : variable label `var'
                label variable `var' "`current_label' shr"
            }
            if strpos("`var'", "hq") {
                local current_label : variable label `var'
                label variable `var' "`current_label' HQ"
            }
            if strpos("`var'", "home") {
                local current_label : variable label `var'
                label variable `var' "`current_label' domestic"
            }
            if strpos("`var'", "foreign") {
                local current_label : variable label `var'
                label variable `var' "`current_label' foreign"
            }
            if strpos("`var'", "shr2") {
                local current_label : variable label `var'
                label variable `var' "`current_label' normalized weights"
            }
            if strpos("`var'", "shr4") {
                local current_label : variable label `var'
                label variable `var' "`current_label' normalized all"
            }
            if strpos("`var'", "bia") {
                local current_label : variable label `var'
                label variable `var' "`current_label' biadic"
            }
            if strpos("`var'", "rm6") {
                local current_label : variable label `var'
                label variable `var' "`current_label' refined"
            }
            if strpos("`var'", "iw") {
                local current_label : variable label `var'
                label variable `var' "`current_label' inventor-weighted"
            }
        }
	}	
end
